import java.io.FileOutputStream;

public class MyHist extends Share {
	static String HOME = "../resgod/IHist";
	static byte[][] bb;
	static int index = 0;

	public static void main(String[] args) {
		checkArgs(args);

		if (args[2].contains("tes")) {
			bb = new byte[7][6 * 1000990];
		} else {
			bb = new byte[7][4 * 1000990];
		}

		initialize(HOME);

		if (bUserID == 0) {
			header();
		}

		long time = System.currentTimeMillis();
		loop();
		System.out.println("Time: " + (System.currentTimeMillis() - time));

		pw.close();

		for (int i = 0; i < 7; i++) {
			try {
				FileOutputStream fos = new FileOutputStream(HOME + "/"
						+ args[2] + "/" + i + ".bin");
				fos.write(bb[i]);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	static void header() {
		String H = "";
//		H += "Ub.__0,Ub._30,Ub._50,Ub._70,Ub._80,Ub._90,Ub.100,";
		H += "Ib.__0,Ib._30,Ib._50,Ib._70,Ib._80,Ib._90,Ub.100";
		println(H);
	}

	static void loop() {
		for (; bUserID < bStop; bUserID++) {
			int v = 0;

			for (int bItemID : USERB[bUserID].items) {
//				hist(USERA[bUserID].votes);
				hist(ITEMA[bItemID].votes);
//				println("");
				v++;
			}
		}
	}

	static void hist(byte[] votes) {
		double b0 = 0;
		double b30 = 0;
		double b50 = 0;
		double b70 = 0;
		double b80 = 0;
		double b90 = 0;
		double b100 = 0;

		for (byte vote : votes) {
			if (vote < 15)
				b0++;
			else if (vote < 45)
				b30++;
			else if (vote < 60)
				b50++;
			else if (vote < 75)
				b70++;
			else if (vote < 85)
				b80++;
			else if (vote < 95)
				b90++;
			else
				b100++;
		}

		bb[0][index] = (byte) (b0 / votes.length * 100);
		bb[1][index] = (byte) (b30 / votes.length * 100);
		bb[2][index] = (byte) (b50 / votes.length * 100);
		bb[3][index] = (byte) (b70 / votes.length * 100);
		bb[4][index] = (byte) (b80 / votes.length * 100);
		bb[5][index] = (byte) (b90 / votes.length * 100);
		bb[6][index] = (byte) (b100 / votes.length * 100);
		index++;

		print(b0 / votes.length * 100);
		print(b30 / votes.length * 100);
		print(b50 / votes.length * 100);
		print(b70 / votes.length * 100);
		print(b80 / votes.length * 100);
		print(b90 / votes.length * 100);
		println(b100 / votes.length * 100);
	}
}
